<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minDays = function (bloomDay, m, k) {
      // 当天数为 day 的时候，是否存在至少 m 个 连续的长为 k 的窗口
      function getTrue(days) {
        let temp = 0
        let count = 0
        for (let item of bloomDay) {
          if (item <= days) {
            temp++
            if (temp === k) {
              // 符合要求了
              count++
              temp = 0
            }
          } else {
            temp = 0
          }
        }
        // 是否已经完成了 m 束花
        return count >= m
      }
      if (m * k > bloomDay.length) return -1
      let left = 1
      let right = Math.max(...bloomDay)
      while (left <= right) {
        let mid = left + ((right - left) >> 1)
        if (getTrue(mid)) {
          // 符合要求，则向左侧逼近
          right = mid - 1
        } else {
          left = mid + 1
        }
      }
      return left
    }
    console.log(minDays(bloomDay = [1, 10, 3, 10, 2], m = 3, k = 1))
  </script>
</body>

</html>